import { message } from "ant-design-vue";
import { getUserInfoApi } from "./../api/user";
import { createStore } from "vuex";
import { getMenuApi } from "@/api/access";

export default createStore({
    state: {
        userInfo: {},
        menus: [],
        error: {},
        requesting: false,
    },
    mutations: {
        changeUserInfo(state, value) {
            state.userInfo = value;
        },
        changeMenus(state, value) {
            state.menus = value;
        },
        changeError(state, value) {
            state.error = value;
        },
        changeRequesting(state, value) {
            state.requesting = value;
        },
    },
    actions: {
        getUserInfo({ commit }) {
            return getUserInfoApi().then(res => {
                if (res.code === 200) {
                    commit("changeUserInfo", res.data);
                }
            });
        },
        getMenu({ commit }) {
            return getMenuApi()
                .then(res => {
                    if (res.code === 200) {
                        commit("changeMenus", res.data);
                    }
                })
        },
    },
    modules: {},
});
